package com.ruoyi.project.gxgw_modules.material.service;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.gxgw_modules.common.DelFlag;
import com.ruoyi.project.gxgw_modules.material.domain.Material;
import com.ruoyi.project.gxgw_modules.material.mapper.MaterialMapper;
import com.ruoyi.project.gxgw_modules.material.vo.MaterialVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.support.Convert;

/**
 * 耗材 服务层实现
 * 
 * @author ruoyi
 * @date 2019-01-17
 */
@Service
public class MaterialServiceImpl implements IMaterialService 
{
	@Autowired
	private MaterialMapper materialMapper;

	/**
     * 查询耗材信息
     * 
     * @param matId 耗材ID
     * @return 耗材信息
     */
    @Override
	public Material selectMaterialById(Integer matId)
	{
	    return materialMapper.selectMaterialById(matId);
	}
	
	/**
     * 查询耗材列表
     * 
     * @param material 耗材信息
     * @return 耗材集合
     */
	@Override
	public List<MaterialVO> selectMaterialList(MaterialVO material)
	{
	    return materialMapper.selectMaterialList(material);
	}
	
    /**
     * 新增耗材
     * 
     * @param material 耗材信息
     * @return 结果
     */
	@Override
	public int insertMaterial(Material material)
	{
		Date now = new Date();
		Long userId = ShiroUtils.getUserId();
		material.setCreateBy(userId.toString());
		material.setUpdateBy(userId.toString());
		material.setUpdateDate(now);
		material.setDelFlag(DelFlag.ALIVE.getCode());
	    return materialMapper.insertMaterial(material);
	}
	
	/**
     * 修改耗材
     * 
     * @param material 耗材信息
     * @return 结果
     */
	@Override
	public int updateMaterial(Material material)
	{
		Date now = new Date();
		Long userId = ShiroUtils.getUserId();
		material.setUpdateBy(userId.toString());
		material.setUpdateDate(now);
	    return materialMapper.updateMaterial(material);
	}

	/**
     * 删除耗材对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteMaterialByIds(String ids)
	{
		return materialMapper.deleteMaterialByIds(Convert.toStrArray(ids));
	}
	
}
